package com.yhz.openapi.web.controller;

import com.yhz.openapi.common.Const;
import com.yhz.openapi.common.ResponseResult;
import com.yhz.openapi.entity.AdminUser;
import com.yhz.openapi.entity.Menu;
import com.yhz.openapi.services.MenuServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuServices menuServices;

    @RequestMapping("getMenu")
    public ResponseResult getMenu(HttpSession session){
        AdminUser user = (AdminUser) session.getAttribute(Const.IS_LOGIN);
        if (user == null) {
            return ResponseResult.getFail("请先登录");
        }
        //访问数据库获取用户有权访问的菜单
        List<Menu> menus=menuServices.getMenuByUid(user.getId());
        return  ResponseResult.getSuccess(menus);
    }
}
